/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 $(function() {
	
	//===== Hide/show sidebar =====//
	$('#my_name,#my_password').change(function(){$('.account-info .btn-update-myaccount').show();});
	$('.user-menu').click(function(){
		
		if($('.account-info').css('left')==="-254px"){
			$('#marker').stop().show();
			$('.account-info').stop().animate({left:"0px"},750)
		}else{
			$('#marker').click();
		}
	});
	$('#marker').click(function(){
		$(this).stop().hide();
		$('.account-info').stop().animate({left:"-254px"},750);
	});
	$('.fullview').click(function(){
	    $("body").toggleClass("clean");
	    $('#sidebar').toggleClass("hide-sidebar mobile-sidebar");
	    $('#content').toggleClass("full-content");
	});

	//===== Hide/show action tabs =====//

	$('.showmenu').click(function () {
		$('.actions-wrapper').slideToggle(100);
	});

	//===== Generate random values for bars in stats widgets =====//

	function generateNumber(min, max) {
		min = typeof min !== 'undefined' ? min : 1;
		max = typeof max !== 'undefined' ? max : 100;
		return Math.floor((Math.random() * max) + min);
	};

	//===== Tooltips =====//

	$('.tip').tooltip();
	$('.focustip').tooltip({'trigger':'focus'});
	
	//===== Easy tabs =====//
	
	$('.sidebar-tabs').easytabs({
		animationSpeed: 150,
		collapsible: false,
		tabActiveClass: "active"
	});

	$('.actions').easytabs({
		animationSpeed: 300,
		collapsible: false,
		tabActiveClass: "current"
	});

	//===== Make Google maps visible inaide tabs =====//

	function initialize()
	{
		var mapProp= {
			center: new google.maps.LatLng(-37.814666,144.982452),
			zoom: 12,
			mapTypeId:google.maps.MapTypeId.ROADMAP
		};
		var map=new google.maps.Map(document.getElementById("google-map"),mapProp);

		$('.actions').bind('easytabs:after', function() {
			google.maps.event.trigger(map, 'resize');
			map.setCenter(new google.maps.LatLng(-37.814666,144.982452));
		});

	};
	//google.maps.event.addDomListener(window, 'load', initialize);

	//===== Collapsible plugin for main nav =====//
	
	/*$('.expand').collapsible({
		defaultOpen: 'current,third',
		cookieName: 'navAct',
		cssOpen: 'subOpened',
		cssClose: 'subClosed',
		speed: 200
	});*/

	//===== Form elements styling =====//
	/*$(".ui-datepicker-month, .styled, .dataTables_length select").uniform({ radioClass: 'choice' });*/
});

function random_mypass(){
    new backend({
        url: base_url + 'cms/user/randomstring',
        data: {},
        callback: function(rsdata) {
            if (rsdata.result < 0) {
                $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
            } else {
                $('#my_password').val(rsdata.message);
            }
        }
    }).call();
}
function update_me(){
    if($('#my_name').val()=='')return;
    new backend({
        url: base_url + 'cms/user/update_me',
        data: {
            Params:{
                ause_name:$('#my_name').val(),
                ause_password:$('#my_password').val()
            }
        },
        callback: function(rsdata) {
            if (rsdata.result < 0) {
                $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
            } else {
                $.jGrowl(rsdata.message);
                $('#my_password').val('');
            }
        }
    }).call();
}
function dialog_user(){
    $('#dialog-user>.base-dialog-modal').html('<div class="base_loading" style="display: block;height: 60px"></div>');
    bckdialog({
        title:'My Profile',
        message:$('#dialog-user'),
        buttons: [
            {
                text    :'Save',
                class   :'base_button base_green base-small-border-radius',
                click   : function() {
                    update_me();
                }
            },
            {
                text    :'Close',
                class   :'base_button',
                click   : function() {
                    $(this).dialog("close");
                }
            }
        ]
    }).open();
    $('#dialog-user>.base-dialog-modal').load(base_url+ 'backend/user/my_profile',function(){
        //$("#my_password").jqxPasswordInput({ theme: theme, width: '300px', height: '20px', showStrength: true, showStrengthPosition: "right" });
        $('#dialog-user').dialog("close").dialog("open");
        
    });
}
function dialog_notication(){
    var _dialog = $('#dialog-notications');
    bckdialog({
        title:'Messages',
        message:$('#dialog-notications'),
        buttons: [
            {
                text    :'Refresh',
                class   :'base_button base_green base-small-border-radius',
                click   : function() {
                    
                }
            },{
                text    :'Cancel',
                class   :'base_button base_red base-small-border-radius',
                click   : function() {
                    $(this).dialog("close");
                }
            }
        ]
    }).open();
    
}
function see_message(that,Id){
    $(that).hide();
    $(that).parent().next().show();
    new backend({
        url: base_url + "cms/excution/commit/contact/contact/cont",
        data: {
            Id: Id,
            Params: {
                cont_delete:'2013-12-05 00:00:00'
            }
        },
        callback: function(rsdata) {
            PENDING = false;
        }
    }).call();
}
